package com.yawn.demomybatisxml.controller;

import com.yawn.demomybatisxml.entity.Person;
import com.yawn.demomybatisxml.mapper.PersonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PersonController {

    @Autowired
    private PersonMapper personMapper;

    @GetMapping("get")
    public Person get(int id) {
        return personMapper.get(id);
    }
    @GetMapping("list")
    public List<Person> list() {
        return personMapper.list();
    }

    @PostMapping("add")
    public int add(@RequestBody Person person) {
        System.out.println(person);
        int result = personMapper.add(person);
        System.out.println(person);
        return result;
    }
}
